//
//  addBunkCardController.m
//  SSSAllRollAgency
//
//  Created by Darker on 2017/3/15.
//  Copyright © 2017年 Darker. All rights reserved.
//

#import "addBunkCardController.h"
#import "NSString+ZDMD5Secret.h"

@interface addBunkCardController ()<QMUITextFieldDelegate>
{
    QMUITextField *_nameTextField;//姓名
    QMUITextField *_indfTextField;//身份证
    QMUITextField *_bunkNumberTextField;//银行卡号
    QMUITextField *_codeTextField;//验证码
    UIButton *_codeBtn;
    NSString *_codeStr;//验证码验证字符串
    UILabel *bunkLabel;
    NSString *bankId;
    NSString *bankName;
    NSString *cardName;
    NSString *cardType;
}
@end

@implementation addBunkCardController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.title = @"绑定银行卡";
    //去掉透明后导航栏下边的黑边
    //    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = [UIColor colorWithHex:@"F9F9FA"];
    [ZDAlertView showToastViewWithTitle:@"温 馨 提 示" message:@"目前只能添加邮政银行储蓄卡" duration:2 dismissCompletion:^(NSInteger buttonIndex) {
        NSLog(@"关闭");
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpApperance];
    
}
- (void)setUpApperance{
    
    UIView *headerView = [[UIView alloc]init];
    [self.view addSubview:headerView];
    headerView.backgroundColor = [UIColor colorWithHex:@"FFFFFF"];
    headerView.layer.borderColor = [UIColor colorWithHex:@"E5E5E8"].CGColor;
    headerView.layer.borderWidth = 0.5;
    headerView.sd_layout
    .topSpaceToView(self.view,HeigthIos6CompeteWithCurrent(10) + 64)
    .leftEqualToView(self.view)
    .rightEqualToView(self.view)
    .heightIs(HeigthIos6CompeteWithCurrent(51));
    
    UILabel *phoneLabel = [[UILabel alloc]init];
    phoneLabel.text = [SSSUserManager getUserModel].phone;
    phoneLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    phoneLabel.textAlignment = NSTextAlignmentLeft;
    phoneLabel.font = [SSSFont systemFontOfSize:16];
    [headerView addSubview:phoneLabel];
    phoneLabel.sd_layout
    .centerYEqualToView(headerView)
    .leftSpaceToView(headerView,WidthIos6CompeteWithCurrent(25))
    .autoHeightRatio(0)
    .widthIs(WidthIos6CompeteWithCurrent(200));
    
    
    _nameTextField = [[QMUITextField alloc]init];
    //_nameTextField.returnKeyType = UIReturnKeyDone;
    //_nameTextField.delegate = self;
    _nameTextField.font = [SSSFont systemFontOfSize:14];
    [self.view addSubview:_nameTextField];
    [_nameTextField setValue:[UIColor colorWithHex:@"BBBBBB"] forKeyPath:@"_placeholderLabel.textColor"];
    _nameTextField.placeholder = @"请输入持卡人姓名";
    _nameTextField.textColor = [UIColor blackColor];
    _nameTextField.layer.borderWidth = 0.5;
    _nameTextField.layer.borderColor = [[UIColor grayColor]colorWithAlphaComponent:0.3].CGColor;
    _nameTextField.layer.cornerRadius = HeigthIos6CompeteWithCurrent(10);
    _nameTextField.layer.masksToBounds = YES;
    // 设置文本框的清除按钮的模式
    _nameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    // 设置文本框的清楚按钮的模式
    _nameTextField.clearsOnBeginEditing = YES;
    // 设置文本框的光标颜色
    _nameTextField.tintColor = [UIColor colorWithHex:@"44b034"];
    _nameTextField.sd_layout
    .topSpaceToView(headerView,HeigthIos6CompeteWithCurrent(20))
    .leftSpaceToView(self.view,WidthIos6CompeteWithCurrent(43))
    .rightSpaceToView(self.view,WidthIos6CompeteWithCurrent(43))
    .heightIs(HeigthIos6CompeteWithCurrent(51));
    
    
    _indfTextField = [[QMUITextField alloc]init];
    _indfTextField.returnKeyType = UIReturnKeyDone;
    //_indfTextField.delegate = self;
    _indfTextField.font = [SSSFont systemFontOfSize:14];
    [self.view addSubview:_indfTextField];
    [_indfTextField setValue:[UIColor colorWithHex:@"BBBBBB"] forKeyPath:@"_placeholderLabel.textColor"];
    _indfTextField.placeholder = @"请输入持卡人身份证号码";
    _indfTextField.textColor = [UIColor blackColor];
    _indfTextField.layer.borderWidth = 0.5;
    _indfTextField.layer.borderColor = [[UIColor grayColor]colorWithAlphaComponent:0.3].CGColor;
    _indfTextField.layer.cornerRadius = HeigthIos6CompeteWithCurrent(10);
    _indfTextField.layer.masksToBounds = YES;
    // 设置文本框的清楚按钮的模式
    _indfTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    // 设置文本框的清楚按钮的模式
    _indfTextField.clearsOnBeginEditing = YES;
    // 设置文本框的光标颜色
    _indfTextField.tintColor = [UIColor colorWithHex:@"44b034"];
    _indfTextField.sd_layout
    .topSpaceToView(_nameTextField,HeigthIos6CompeteWithCurrent(20))
    .leftSpaceToView(self.view,WidthIos6CompeteWithCurrent(43))
    .rightSpaceToView(self.view,WidthIos6CompeteWithCurrent(43))
    .heightIs(HeigthIos6CompeteWithCurrent(51));
    
    
    _bunkNumberTextField = [[QMUITextField alloc]init];
    _bunkNumberTextField.returnKeyType = UIReturnKeyDone;
    _bunkNumberTextField.delegate = self;
    _bunkNumberTextField.font = [SSSFont systemFontOfSize:14];
    [self.view addSubview:_bunkNumberTextField];
    [_bunkNumberTextField setValue:[UIColor colorWithHex:@"BBBBBB"] forKeyPath:@"_placeholderLabel.textColor"];
    _bunkNumberTextField.placeholder = @"请输入本人的银行卡号";
    _bunkNumberTextField.textColor = [UIColor blackColor];
    _bunkNumberTextField.layer.borderWidth = 0.5;
    _bunkNumberTextField.layer.borderColor = [[UIColor grayColor]colorWithAlphaComponent:0.3].CGColor;
    _bunkNumberTextField.layer.cornerRadius = HeigthIos6CompeteWithCurrent(10);
    _bunkNumberTextField.layer.masksToBounds = YES;
    _bunkNumberTextField.keyboardType = UIKeyboardTypePhonePad;
    // 设置文本框的清楚按钮的模式
    _bunkNumberTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    // 设置文本框的清楚按钮的模式
    _bunkNumberTextField.clearsOnBeginEditing = YES;
    // 设置文本框的光标颜色
    _bunkNumberTextField.tintColor = [UIColor colorWithHex:@"44b034"];
    _bunkNumberTextField.sd_layout
    .topSpaceToView(_indfTextField,HeigthIos6CompeteWithCurrent(20))
    .leftSpaceToView(self.view,WidthIos6CompeteWithCurrent(43))
    .rightSpaceToView(self.view,WidthIos6CompeteWithCurrent(43))
    .heightIs(HeigthIos6CompeteWithCurrent(51));
    
    bunkLabel = [[UILabel alloc]init];
    bunkLabel.text = @"开户行：中国工商银行";
    bunkLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    bunkLabel.textAlignment = NSTextAlignmentLeft;
    bunkLabel.font = [SSSFont systemFontOfSize:15];
    [self.view addSubview:bunkLabel];
    bunkLabel.sd_layout
    .topSpaceToView(_bunkNumberTextField,HeigthIos6CompeteWithCurrent(12))
    .leftSpaceToView(self.view,WidthIos6CompeteWithCurrent(59))
    .heightIs(HeigthIos6CompeteWithCurrent(20))
    .rightSpaceToView(self.view,HeigthIos6CompeteWithCurrent(10));
    
    _codeTextField = [[QMUITextField alloc]init];
    _codeTextField.returnKeyType = UIReturnKeyDone;
    //_codeTextField.delegate = self;
    _codeTextField.font = [SSSFont systemFontOfSize:14];
    [self.view addSubview:_codeTextField];
    _codeTextField.placeholder = @"请输入验证码";
    _codeTextField.textColor = [UIColor blackColor];
     [_codeTextField setValue:[UIColor colorWithHex:@"BBBBBB"] forKeyPath:@"_placeholderLabel.textColor"];
    _codeTextField.layer.borderWidth = 0.5;
    _codeTextField.layer.borderColor = [[UIColor grayColor]colorWithAlphaComponent:0.3].CGColor;
    _codeTextField.layer.cornerRadius = HeigthIos6CompeteWithCurrent(10);
    _codeTextField.layer.masksToBounds = YES;
    _codeTextField.keyboardType = UIKeyboardTypePhonePad;
    // 设置文本框的清楚按钮的模式
    _codeTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    // 设置文本框的清楚按钮的模式
    _codeTextField.clearsOnBeginEditing = YES;
    // 设置文本框的光标颜色
    _codeTextField.tintColor = [UIColor colorWithHex:@"44b034"];
    _codeTextField.sd_layout
    .topSpaceToView(bunkLabel,HeigthIos6CompeteWithCurrent(12))
    .leftSpaceToView(self.view,WidthIos6CompeteWithCurrent(43))
    .widthIs(WidthIos6CompeteWithCurrent(171))
    .heightIs(HeigthIos6CompeteWithCurrent(51));
    
    _codeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_codeBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
    //_sendAuthCodeBtn.buttonType = UIButtonTypeCustom;
    [self.view addSubview:_codeBtn];
    _codeBtn.titleLabel.font = [SSSFont systemFontOfSize:14];
    _codeBtn.layer.borderColor = [[UIColor grayColor] colorWithAlphaComponent:0.3].CGColor;
    _codeBtn.layer.borderWidth = 0.5;
    _codeBtn.layer.cornerRadius = HeigthIos6CompeteWithCurrent(10);
    _codeBtn.layer.masksToBounds = YES;
    [_codeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    [_codeBtn addTarget:self action:@selector(sendAuthCodeClick) forControlEvents:UIControlEventTouchDown];
    _codeBtn.sd_layout
    .leftSpaceToView(_codeTextField,WidthIos6CompeteWithCurrent(10))
    .topEqualToView(_codeTextField)
    .bottomEqualToView(_codeTextField)
    .rightEqualToView(_bunkNumberTextField);

    //开始绑定按钮
    UIButton *startBuingBtn = [[UIButton alloc]init];
    [startBuingBtn setTitle:@"开 始 绑 定" forState:UIControlStateNormal];
    startBuingBtn.titleLabel.font = [SSSFont systemFontOfSize:20];
    [startBuingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [startBuingBtn setBackgroundColor:[UIColor colorWithHex:@"40B87B"]];
    startBuingBtn.layer.cornerRadius = HeigthIos6CompeteWithCurrent(10);
    startBuingBtn.layer.masksToBounds = YES;
    [startBuingBtn addTarget:self action:@selector(startBtnClick) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:startBuingBtn];
    startBuingBtn.sd_layout
    .topSpaceToView(_codeBtn,HeigthIos6CompeteWithCurrent(40))
    .leftEqualToView(_bunkNumberTextField)
    .rightEqualToView(_bunkNumberTextField)
    .heightIs(HeigthIos6CompeteWithCurrent(51));
    
}
//发送验证码按钮
- (void)sendAuthCodeClick{
    
    
    //NSString *sendCodeUrl = [NSString stringWithFormat:@"%@%@%@%@",SSSCommomUrl,@"user/",simple.userModel.phone,@"/getCode"];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"phone"] = [SSSUserManager getUserModel].phone;
    
    [ZDNetManager zd_requestWithType:ZDHttpRequestTypeGet UrlString:kConfigPath(kGetCode) Parameters:params SuccessBlock:^(id response) {
        
        
        if ([response[@"sataus"] intValue] == 0) {
            
            //倒计时
            [self verificationCodeOfTimer];
            [QMUITips showSucceed:@"获取验证码成功" inView:self.view hideAfterDelay:2];
            
        }else{
            
            [QMUITips showError:response[@"message"] inView:self.view hideAfterDelay:2];
            return ;
        }
        
    } FailureBlock:^(NSError *error) {
        
        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
        
    } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
        
        
    }];

}
- (void)verificationCodeOfTimer{
    
    __block int timeout = 60.0; //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout<=0){ //倒计时结束，关闭
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                [_codeBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
                _codeBtn.userInteractionEnabled = YES;
                _codeBtn.enabled = YES;
                [_codeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                _codeBtn.layer.borderColor = [[UIColor grayColor] colorWithAlphaComponent:0.3].CGColor;
                _codeBtn.layer.borderWidth = 0.5;
            });
            
        }else{
            int seconds = (timeout-1) % 60;
            NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                //NSLog(@"____%@",strTime);
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:1];
                //                NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:str];
                //                //                [AttributedStr addAttribute:NSFontAttributeName
                //                //
                //                //                                      value:[UIFont systemFontOfSize:16.0]
                //                //
                //                //                                      range:NSMakeRange(0, 2)];
                //
                //                [AttributedStr addAttribute:NSForegroundColorAttributeName
                //
                //                                      value:[UIColor blackColor]
                //
                //                                      range:NSMakeRange(0, 2)];
                //                //                [AttributedStr addAttribute:NSForegroundColorAttributeName
                //                //
                //                //                                      value:[UIColor grayColor]
                //                //
                //                //                                      range:NSMakeRange(2,6)];
                //
                
                [_codeBtn setTitle:[NSString stringWithFormat:@"%@秒后重发",strTime] forState:UIControlStateNormal];
                [_codeBtn setTitleColor:[UIColor colorWithHex:@"BBBBBB"]forState:UIControlStateNormal];
                _codeBtn.layer.borderColor = [[UIColor grayColor] colorWithAlphaComponent:0.2].CGColor;
                _codeBtn.layer.borderWidth = 0.5;
                [UIView commitAnimations];
                _codeBtn.userInteractionEnabled = NO;
                _codeBtn.enabled = NO;
            });
            timeout--;
        }
    });
    dispatch_resume(_timer);

}
- (void)startBtnClick{
    //收起键盘
    [_bunkNumberTextField resignFirstResponder];
    [_codeTextField resignFirstResponder];
    [_indfTextField resignFirstResponder];
    [_nameTextField resignFirstResponder];
    
    if ([_nameTextField.text isEqualToString:@""]) {
        [QMUITips showError:@"请输入持卡人姓名" inView:self.view hideAfterDelay:2];
        
        return;
        
    }else if ([_indfTextField.text isEqualToString:@""]){
        
        [QMUITips showError:@"请输入正确的持卡人身份证号码" inView:self.view hideAfterDelay:2];
        return;
        
    }
    else if (![_bunkNumberTextField.text isBankCard:_bunkNumberTextField
               .text]){
        
        [QMUITips showError:@"请输入正确的银行卡号" inView:self.view hideAfterDelay:2];
        return;
        
    }else if ([_codeTextField.text isEqualToString:@""]){
        
        [QMUITips showError:@"请输入正确的验证码" inView:self.view hideAfterDelay:2];
        return;
        
    }else{
        
        //校验验证码
        [self getVerificationCode];
        
    }

    
//    if ([_bunkNumberTextField.text isEqualToString:@""]) {
//        message = @"银行卡号不能为空";
//        return;
//    }else{
//        
//        if (![SSSRegularExpression zd_isBankCardlNumCheck:_bunkNumberTextField.text] || [_bunkNumberTextField.text  isEqual: @""]) {
//            message = @"请输入正确的银行卡号";
//        }else if ([_codeTextField.text isEqualToString:@""]){
//            message = @"请输入验证码";
//            
//        }if(![message isEqualToString:@""]){
//            
//            //验证验证码
//            
//        }else{
//            
//            
//        }
//
//    }
    
}
- (void)getVerificationCode{
    
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"phone"] = [SSSUserManager getUserModel].phone;
    params[@"code"]  = _codeTextField.text;
 
   // NSString *verifcationUrl = [NSString stringWithFormat:@"%@%@%@%@%@%@",SSSCommomUrl,@"user/",simple.userModel.phone,@"/",_codeTextField.text,@"/checkCode"];
    
    [[XHRequestManager manager] postRequest:kConfigPath(kVerifyCode) params:params success:^(id  _Nonnull responseObj) {
        
        if ([responseObj[@"status"] intValue] == 0) {
            
            //上传资料
            [self loadCommitApi];
            
        }else{
            
            [QMUITips showError:responseObj[@"message"] inView:self.view hideAfterDelay:2];
        }

        
    } failure:^(NSError * _Nonnull error) {
        
        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
 
    }];
    
//    [ZDNetManager zd_requestWithType:ZDHttpRequestTypeGet UrlString:kConfigPath(kVerifyCode) Parameters:params SuccessBlock:^(id response) {
//        
//        if ([response[@"status"] intValue] == 0) {
//            
//            //上传资料
//            [self loadCommitApi];
//            
//        }else{
//            
//            [QMUITips showError:response[@"message"] inView:self.view hideAfterDelay:2];
//        }
//        
//    } FailureBlock:^(NSError *error) {
//        
//        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
//        
//    } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
//        
//        
//    }];

}
- (void)reloadGetBankName{
    
   // NSString *bankNameUrl = [NSString stringWithFormat:@"%@%@",SSSCommomUrl,@"user/queryBankName"];
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"bankCardNo"] = _bunkNumberTextField.text;
    
    [[XHRequestManager manager] getRequest:kConfigPath(kgetBunkName) params:dict success:^(id  _Nonnull responseObj) {
        
        XHLog(@"---bankName%@",responseObj);
        if ([responseObj[@"status"] intValue] == 0) {
            
            //回到主线程刷新表格
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //bunkLabel.text = response[@"data"][@"bank_name"];
                bankId = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"bank_id"]];
                bankName = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"bank_name"]];
                cardType = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"card_type"]];
                cardName = [NSString stringWithFormat:@"%@",responseObj[@"data"][@"card_name"]];
                
            });
            
        }else{
            
            [QMUITips showError:responseObj[@"message"] inView:self.view hideAfterDelay:2];
        }

        
    } failure:^(NSError * _Nonnull error) {
        
        XHLog(@"%@",error.localizedDescription);
        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
        
    }];
    
//    [ZDNetManager zd_requestWithType:ZDHttpRequestTypeGet UrlString:kConfigPath(kgetBunkName) Parameters:dict SuccessBlock:^(id response) {
//        
//        XHLog(@"---bankName%@",response);
//        if ([response[@"status"] intValue] == 0) {
//            
//            //回到主线程刷新表格
//            dispatch_async(dispatch_get_main_queue(), ^{
//                
//                //bunkLabel.text = response[@"data"][@"bank_name"];
//                bankId = [NSString stringWithFormat:@"%@",response[@"data"][@"bank_id"]];
//                bankName = [NSString stringWithFormat:@"%@",response[@"data"][@"bank_name"]];
//                cardType = [NSString stringWithFormat:@"%@",response[@"data"][@"card_type"]];
//                cardName = [NSString stringWithFormat:@"%@",response[@"data"][@"card_name"]];
//                
//            });
//            
//        }else{
//            
//            [QMUITips showError:response[@"message"] inView:self.view hideAfterDelay:2];
//        }
//        
//    } FailureBlock:^(NSError *error) {
//        
//        XHLog(@"%@",error.localizedDescription);
//        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
//        
//    } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
//        
//        
//    }];
    
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    
    
    [self reloadGetBankName];
}
//提交
- (void)loadCommitApi{
    
    // [QMUITips showSucceed:@"提交成功" inView:self.view hideAfterDelay:2];
    
   // NSString *addBunkUrl = [NSString stringWithFormat:@"%@%@%@%@%@%@%@%@",SSSCommomUrl,@"user/",_bunkNumberTextField.text,@"/",simple.userModel.phone,@"/",_codeTextField.text,@"/addBankCard"];
    NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
    parameter[@"bankCardNo"] = _bunkNumberTextField.text;
    parameter[@"phone"] = [SSSUserManager getUserModel].phone;
    parameter[@"name"] = _nameTextField.text;
    parameter[@"identifyCard"] = _indfTextField.text;
    parameter[@"bankId"] = bankId;
    parameter[@"bankName"] = bankName;
    parameter[@"cardType"] = cardType;
    parameter[@"cardName"] = cardName;
    
    [[XHRequestManager manager] postRequest:kConfigPath(kAddBunkCard) params:parameter success:^(id  _Nonnull responseObj) {
        
        if ([responseObj[@"sataus"] intValue] == 0) {
            
            [QMUITips showSucceed:@"绑定成功" inView:self.view hideAfterDelay:2];
            
        }else{
            
            [QMUITips showError:responseObj[@"message"] inView:self.view hideAfterDelay:2];
            return ;
        }

        
    } failure:^(NSError * _Nonnull error) {
        
        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
    }];
    
//    [ZDNetManager zd_requestWithType:ZDHttpRequestTypePost UrlString:kConfigPath(kAddBunkCard) Parameters:nil SuccessBlock:^(id response) {
//        
//        if ([response[@"sataus"] intValue] == 0) {
//            
//            [QMUITips showSucceed:@"绑定成功" inView:self.view hideAfterDelay:2];
//            
//        }else{
//            
//            [QMUITips showError:response[@"message"] inView:self.view hideAfterDelay:2];
//            return ;
//        }
//        
//        
//    } FailureBlock:^(NSError *error) {
//        
//        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
//    } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
//        
//        
//    }];
    
    
}

////检测是否为纯数字
//- (BOOL)isPureInt:(NSString *)string{
//    NSScanner* scan = [NSScanner scannerWithString:string];
//    int val;
//    return [scan scanInt:&val] && [scan isAtEnd];
//}
//在UITextField的代理方法中
//- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
//    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容
//    //检测是否为纯数字
//    if ([self isPureInt:string]) {
//        //添加空格，每4位之后，4组之后不加空格，格式为xxxx xxxx xxxx xxxx xxxxxxxxxxxxxx
//        if (textField.text.length % 5 == 4 && textField.text.length < 22) {
//            textField.text = [NSString stringWithFormat:@"%@ ", textField.text];
//        }
//        //只要30位数字
//        if ([toBeString length] >= 19+4+11)
//        {
//            toBeString = [toBeString substringToIndex:19+4+11];
//            textField.text = toBeString;
//            [textField resignFirstResponder];
//            return NO;
//        }
//    }
//    else if ([string isEqualToString:@""]) { // 删除字符
//        if ((textField.text.length - 2) % 5 == 4 && textField.text.length < 22) {
//            textField.text = [textField.text substringToIndex:textField.text.length - 1];
//        }
//        return YES;
//    }
//    else{
//        return NO;
//    }
//    return YES;
//}

//收起键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [_bunkNumberTextField resignFirstResponder];
    [_codeTextField resignFirstResponder];
    [_indfTextField resignFirstResponder];
    [_nameTextField resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
